<?php
/**
 * 微信支付 JS_API支付页面
 * ====================================================
*/

defined('InShopNC') or exit('Access Invalid!');

require_once BasePath.'/api/gold_payment/wxpay/WxPayHelper.php';

class js_api_callControl extends MobileControl{

	public function indexOp(){
		$sql = "SELECT * FROM #__gold_payment WHERE payment_code = 'wxpay'";
		$payment_info = Db::queryRow($sql);
		$payment_info['payment_config'] = unserialize($payment_info['payment_config']);
		$pdr_sn = $_GET['state'];
		$sql = "SELECT pdr_price FROM #__predeposit_recharge WHERE pdr_sn = '$pdr_sn'";
		$order_info = Db::queryRow($sql);
		$order_info['order_sn'] = $pdr_sn;
		
		$jsApi = new JsApi_pub($payment_info,$order_info);
		//获取code码，以获取openid
		$code = $_GET['code'];
		$jsApi->setCode($code);
		$openid = $jsApi->getOpenId();
		
		//=========步骤2：使用统一支付接口，获取prepay_id============
		//使用统一支付接口
		$unifiedOrder = new UnifiedOrder_pub($payment_info,$order_info);
		//设置统一支付接口参数
		$unifiedOrder->setParameter("openid",$openid);
		$unifiedOrder->setParameter("body",$unifiedOrder->order['order_sn']);//商品描述
		$out_trade_no = $unifiedOrder->order['order_sn'];
		$unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号 
		$unifiedOrder->setParameter("total_fee",($unifiedOrder->order['pdr_price']*100));//总金额
		$unifiedOrder->setParameter("notify_url",$unifiedOrder->notify_url);//通知地址 
		$unifiedOrder->setParameter("trade_type","JSAPI");//交易类型
		$prepay_id = $unifiedOrder->getPrepayId();
		//=========步骤3：使用jsapi调起支付============
		$jsApi->setPrepayId($prepay_id);
		$jsApiParameters = $jsApi->getParameters();
		
		Tpl::output('jsApiParameters',$jsApiParameters);
		Tpl::showpage('js_api_call');
	}

}


?>